package com.exm.sql.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.exm.sql.mapper.UserMapper;
import com.exm.sql.model.User;
import com.exm.sql.repository.UserRepository;
import org.springframework.stereotype.Service;

@Service
public class UserRepositoryImpl  extends ServiceImpl<UserMapper, User> implements UserRepository {

    @Override
    public User getUserByAccount(String account) {
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(User::getAccount,account);
        User user = getOne(queryWrapper);
        return user;
    }

    @Override
    public Boolean setUserByAccount(User user) {
        LambdaUpdateWrapper<User> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(User::getAccount,user.getAccount());
        boolean update = update(user, updateWrapper);
        return update;
    }

    @Override
    public long getUserCountByAccount(String account) {
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(User::getAccount,account);
        long count = count(queryWrapper);
        return count;
    }
}